package com.csr.csrcheck.controller;

import com.csr.csrcheck.pojo.Feedback;
import com.csr.csrcheck.service.FeedbackService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.util.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RequestMapping({"feeedback"})
@RestController
public class FeedbackController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.FeedbackController.class);

    @Resource
    private FeedbackService feedbackService;

    @GetMapping({"add"})
    public JsonResult<Void> feeedback(Feedback feedback) {
        if (feedback.getContent().equals("") || feedback.getInformation().equals(""))
            throw new CompanyException("");
                    String data = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
        feedback.setCommitdata(data);
        this.feedbackService.addfeedback(feedback);
        log.info("add--------------->feedback" + feedback);
        log.info("add--------------->Commitdata" + data);
        return new JsonResult(Integer.valueOf(0), "json");
    }

    @RequestMapping({"list"})
    public JsonResult<List<Feedback>> list() {
        List<Feedback> list = this.feedbackService.getfeedback();
        return new JsonResult(Integer.valueOf(0), "json", list);
    }
}
